package com.atguigu.stgy.admin.controller;

import com.atguigu.stgy.admin.service.RoomInfoService;
import com.atguigu.stgy.model.dto.ApartmentSearchDTO;
import com.atguigu.stgy.model.dto.RoomDTO;
import com.atguigu.stgy.model.entity.RoomInfo;
import com.atguigu.stgy.model.result.R;
import com.atguigu.stgy.model.vo.RoomVO;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 房间信息表(room_info)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/admin/room")
public class RoomInfoController {
    /**
     * 服务对象
     */
    @Resource
    private RoomInfoService roomInfoService;
    ///admin/room/listBasicByApartmentId?id=10
    @Operation(summary = "查询公寓下的房屋列表")
    @GetMapping("listBasicByApartmentId")
    public R<List<RoomInfo>> pageItem(@RequestParam("id") Long apartmentId){
        List<RoomInfo> roomInfos = roomInfoService.list(Wrappers.lambdaQuery(RoomInfo.class)
                .eq(RoomInfo::getApartmentId , apartmentId));
        return R.ok(roomInfos);
    }
    ///admin/room/pageItem?current=1&size=10
    @Operation(summary = "条件查询房屋列表信息")
    @GetMapping("pageItem")
    public R<Page<RoomVO>> pageItem(ApartmentSearchDTO searchDTO){
        Page<RoomVO> page = roomInfoService.pageItem(searchDTO);
        return R.ok(page);
    }
    ///admin/room/saveOrUpdate
    @Operation(summary = "新增/更新 房屋信息")
    @PostMapping("saveOrUpdate")
    public R saveOrUpdate(@RequestBody RoomDTO roomDTO){
        roomInfoService.saveOrUpdateRoomDTO(roomDTO);
        return R.ok();
    }


}
